package com.tanhua.server.task;


import com.tanhua.commons.constant.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
@Slf4j
public class ClearTask {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Scheduled(cron = "0 0 0 */1 * ?")
    public void analysis(){
        log.info("后台清理redis任务开始执行.....");
        Set<String> skeys = stringRedisTemplate.keys(Constants.VOICE_SEND_KEY+"*");
        Set<String> lkeys = stringRedisTemplate.keys(Constants.VOICE_LISTEN_KEY+"*");
        for (String key : skeys) {
            stringRedisTemplate.delete(key);
        }
        for (String key : lkeys) {
            stringRedisTemplate.delete(key);
        }
        log.info("后台清理redis任务完成!!!");
    }
}
